<?
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/


function DisplayBooleanTabularHistoryData($nServerModuleID, $nType)
{
	switch ($nType)
	{
		case 1:
			$sTitle = "Last 24 Hours";
			$nStartTime = time()-86400;
			$sType = "";
			break;
		case 2:
			$sTitle = "Last 3 Days";
			$nStartTime = time()- (86400 * 3);
			$sType = "bool15";
			break;
		case 3:
			$sTitle = "Last 1 Week";
			$nStartTime = time()- (86400 * 7);
			$sType = "bool60";
			break;
		case 4:
			$sTitle = "Last 1 Month";
			$nStartTime = time()- (86400 * 30);
			$sType = "bool60";
			break;
		case 5:
			$sTitle = "Last 6 Months";
			$nStartTime = time()- (86400 * 30 * 6);
			$sType = "bool180";
			break;
		case 6:
			$sTitle = "Last 1 Year";
			$nStartTime = time()- (86400 * 365);
			$sType = "bool180";
			break;
		default:
			$nType = 1;
			$sTitle = "Last 24 Hours";
			$nStartTime = time()-86400;
			$sType = "";
			break;
	}
	
	//$aRange = $GLOBALS["BigDaddyHistory"]->GetHistoryRange($nServerModuleID, $nStartTime, $sType);
	
	$aInfo = $GLOBALS["BigDaddyHistory"]->GetBooleanHistoryByTime($nServerModuleID, $nStartTime, $sType, time(), true);
	$nTotal = $aInfo["monitoringend"] - $aInfo["monitoringstart"];
	//var_dump($aInfo["valuetime"]);

	?>
	
	<style>
	.booleandata td
	{
		font-size: 8pt;
		font-family: verdanaa, tahoma, arial, sans serif;
	}
	
	.booleandata .time
	{
		background-color: #ddd;
		padding: 5px;
	}
	
	.booleandata .timelabel
	{
		font-weight: bold;
	}
	
	.booleantitle
	{
	    font-size: 12pt;
		border-bottom: 1px solid #aaa;
		padding-bottom: 5px;
	}
	
	.booleanrange
	{
	    font-size:9pt;
	}
	</style>
	
	<?
	$sAddressString = $_SERVER["PHP_SELF"]."?page=ServerModuleBooleanHistory&type=".$nType."&serverID=".$_REQUEST["serverID"]."&modID=".$_REQUEST["modID"]."&ID=".$_REQUEST["ID"];
	?>
	
	<div class="booleantitle"><b><?=$sTitle;?></b><br>
	<span class="booleanrange">Monitoring Range: <?=get_time_str($aInfo["monitoringstart"], 2);?> - <?=get_time_str($aInfo["monitoringend"], 2);?>
	(<a href="<?=$_SERVER["PHP_SELF"]."?page=ServerModBoolHistoryDetails&type=".$nType."&serverID=".$_REQUEST["serverID"]."&modID=".$_REQUEST["modID"]."&ID=".$_REQUEST["ID"];?>">view details</a>)</span></div>
	

	<table cellpadding="2" width="400" class="booleandata">
	<?
	if ($aInfo["valuetime"]["1"] > 0)
	{
		?>
		<tr class="time">
			<td class="timelabel">Uptime</td>
			<td><?=convertTimeToHours($aInfo["valuetime"]["1"]);?> / <? echo @round( ($aInfo["valuetime"]["1"]/$nTotal*100), 3);?>%</td>
		</tr>
		<?
	}

	if ($aInfo["valuetime"]["-1"] > 0)
	{
		?>
	<tr class="time">
		<td class="timelabel">Scheduled Downtime</td>
		<td><?=convertTimeToHours($aInfo["valuetime"]["-1"]);?> / <? echo @round( ($aInfo["valuetime"]["-1"]/$nTotal*100), 3);?>%</td>
	</tr>
	<?
	}
	if ($aInfo["valuetime"]["0"] > 0)
	{
		?>
	<tr class="time">
		<td class="timelabel">Unscheduled Downtime</td>
		<td><?=convertTimeToHours($aInfo["valuetime"]["0"]);?> / <? echo @round( ($aInfo["valuetime"]["0"]/$nTotal*100), 3);?>%</td>
	</tr>
	<?
	}
	if ($aInfo["valuetime"]["-2"] > 0)
	{
		?>
	<tr class="time">
		<td class="timelabel">No Data (Disabled)</td>
		<td><?=convertTimeToHours($aInfo["valuetime"]["-2"]);?> / <? echo @round( ($aInfo["valuetime"]["-2"]/$nTotal*100), 3);?>%</td>
	</tr>
	<?
	}
	if ($aInfo["valuetime"]["-3"] > 0)
	{
	?>
	<tr class="time">
		<td class="timelabel">No Data (Unknown)</td>
		<td><?=convertTimeToHours($aInfo["valuetime"]["-3"]);?> / <? echo @round( ($aInfo["valuetime"]["-3"]/$nTotal*100), 3);?>%</td>
	</tr>
	<?
	}
	?>
	</table>
	<br>
	<br>
	
	<!-- </td> -->
	<!-- 
	<td>
	<img src="  =$_SERVER["PHP_SELF"]."?page=ServerModuleHistoryBooleanGraph&serverModuleID=$nServerModuleID&starttime=$nStartTime&nType=$nType&stitle=".urlencode($sTitle); */ " />
	
	</td>
	-->
	
	<!-- </tr>
	</table> -->
	
	

	
	<?
}

DisplayBooleanTabularHistoryData($_REQUEST["ID"],1);
DisplayBooleanTabularHistoryData($_REQUEST["ID"],2);
DisplayBooleanTabularHistoryData($_REQUEST["ID"],3);
DisplayBooleanTabularHistoryData($_REQUEST["ID"],4);
DisplayBooleanTabularHistoryData($_REQUEST["ID"],5);
DisplayBooleanTabularHistoryData($_REQUEST["ID"],6);

?>
